#include<bits/stdc++.h>
using namespace std;
const int N=5000;
int T,n,m,L,V,i,j,num=0,ans=0;
int d[N],v[N],a[N],p[N],l[N],r[N],c[N];
inline int read()
{
    int f=1,x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return f*x;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    T=read();
    while(T--)
    {
        n=read(),m=read(),L=read(),V=read();
        ans=0;
        num=0;
        memset(d,0,N),memset(v,0,N),memset(a,0,N),memset(p,0,N),memset(l,0,N),memset(r,0,N),memset(c,0,N);
        for(i=1;i<=n;i++)
        {
            d[i]=read(),v[i]=read(),a[i]=read();
            if(v[i]>V)
            {
                l[i]=d[i];
                if(a[i]>=0) r[i]=L;
                else    r[i]=(V*V-v[i]*v[i]+1)/2/a[i]+d[i];
                c[i]=1;
            }
            else    if(v[i]==V)
            {
                if(a[i]>0)
                {
                    l[i]=d[i]+1;
                    if(l[i]<=L)
                        r[i]=L,c[i]=1;
                    else    c[i]=0;
                }
                else    c[i]=0;
            }
            else
            {
                if(a[i]>0)
                {
                    l[i]=(V*V-v[i]*v[i])/2/a[i]+d[i]+1;
                    if(l[i]<=L)
                        r[i]=L,c[i]=1;
                    else    c[i]=0;
                }
                else    c[i]=0;
            }
            //if(c[i]==1) cout<<i<<endl;
        }
        for(i=1;i<=m;i++)
        {
            p[i]=read();
        }
        for(i=1;i<=n;i++)
        {
            if(c[i]==1)
            {
                for(j=1;j<=m;j++)
                {
                    if(p[j]>=l[i]&&p[j]<=r[i])
                    {
                        c[i]++;
                        if(c[i]==2) num++;
                        ans++;
                    }
                }
            }
        }
        cout<<num<<" "<<ans-num-1<<endl;

    }
}
